﻿using System;
using System.Collections.Generic;
using System.Text;

using GDSJGServer.IndexPushWS;
using GDSJGServer.ProgramePushWS;
using GDSJGServer.IndexCollectWS;
using GDSJGServer.VoucherCollectWS;
using GDSJGServer.ProgramCollectWS;

namespace GDSJGServer
{
    class GDSJKImpl : IDisposable
    {
        public string Execute(string inputs)
        {
            string unitCode = "613001",
                            unitName = "江门市",
                            startTime = "2016",
                            endTime = "2016",
                            vfCode = "AEMT7p8kL9";
            int pageNum = 1;
            string result = "";
            
            string[] data = inputs.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
            string cmd = data[0].Trim();
            if (cmd.Equals("4.1"))
            {
                unitCode = data[1].Trim();
                unitName = data[2].Trim();
                startTime = data[3].Trim();
                endTime = data[4].Trim();
                vfCode = data[5].Trim();
                using (ProgramePushWebService p = new ProgramePushWebService())
                {
                    object re = p.PushProgramTotal(unitCode, unitName, startTime, endTime, vfCode);

                    result = re.ToString();
                }

            }
            else if (cmd.Equals("4.2"))
            {
                unitCode = data[1].Trim();
                unitName = data[2].Trim();
                startTime = data[3].Trim();
                endTime = data[4].Trim();              
                pageNum = int.Parse(data[5].Trim());
                vfCode = data[6].Trim();
                using (ProgramePushWebService p = new ProgramePushWebService())
                {
                    object re = p.PushProgram(unitCode, unitName, startTime, endTime, pageNum , vfCode);

                    result = re.ToString();
                }
                    
            }
            else if (cmd.Equals("5.1"))
            {
                unitCode = data[1].Trim();
                unitName = data[2].Trim();
                startTime = data[3].Trim();
                endTime = data[4].Trim();
                vfCode = data[5].Trim();
                using (JdIndiWebService p = new JdIndiWebService())
                {
                    result = p.PushIndexTotal(unitCode, unitName, startTime, endTime, vfCode);

                }

            }
            else if (cmd.Equals("5.2"))
            {
                unitCode = data[1].Trim();
                unitName = data[2].Trim();
                startTime = data[3].Trim();
                endTime = data[4].Trim();
                pageNum = int.Parse(data[5].Trim());
                vfCode = data[6].Trim();
                using (JdIndiWebService p = new JdIndiWebService())
                {
                    result = p.PushIndex(unitCode, unitName, startTime, endTime, pageNum, vfCode);

                }

            }

            else
            {
                result = "-99999";
            }

            return string.Format("{0}|{1}", cmd, result);
        }


        public void Dispose()
        {

        }
    }
}
